package com.mc.graph;
import java.util.ArrayList;
import java.util.Scanner;

import com.mc.general.Bag;

public class Graph {
	private int V;
	private int E;
	private ArrayList<Bag<Integer>> adj;
	public Graph(int V){
		this.V = V;
		this.E = 0;
		adj = new ArrayList<Bag<Integer>>(V);
	}
	public Graph(Scanner in){
		this(in.nextInt());
		E = in.nextInt();
		for(int i=0;i<E;i++){
			int v = in.nextInt();
			int w = in.nextInt();
			addEdge(v,w);
		}
	}
	public void addEdge(int v,int w){
		adj.get(v).add(w);
		adj.get(w).add(v);
		E++;
	}
	public int V(){
		return V;
	}
	public int E(){
		return E;
	}
	public Iterable<Integer> adj(int v){
		return adj.get(v);
	}
}
